package com.eascs.admin.o2o.loan.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eascs.admin.common.service.BaseSevice;
import com.eascs.admin.o2o.loan.dao.O2oSdDao;
import com.eascs.admin.o2o.loan.entity.O2oSDEntity;
import com.eascs.common.util.StringUtil;
import com.eascs.crm.nsEditDetail.entity.EadbEabaCustomerNew;
import com.eascs.workflow.form.SDEntity;

@Service
public class O2oSdService extends BaseSevice{
	@Autowired
	private O2oSdDao o2oSdDao;
	/**
	 * 保存 SD数据
	 * @param sdEntity
	 * @return
	 */
	public int saveSDEntity(O2oSDEntity sdEntity){
		return o2oSdDao.insert(sdEntity);
	}
	/**
	 * 修改 SD数据
	 * @return
	 */
	public int updateSDEntity(SDEntity o2oSDEntity){
		return o2oSdDao.updateSDEntity(o2oSDEntity);
	}
	/**
	 * id查询实体
	 */
	public O2oSDEntity getById(String loanapplyNo){
		return o2oSdDao.getById(loanapplyNo);
	}
	
	public List<Object[]> getCustomerDataSouce(String keywords) {
		List<Object[]> dataSouceList = new ArrayList<>();
		StringBuffer sql = new StringBuffer("select * from (select CONCAT(t.cno,',',t.cnames,',',t.ccode),t.cnames,t.ccode from eaba_customer_new t where t.sts='PAS' and t.ctype='2'"); 
		//sql.append(" and cname  like ? ");
	     sql.append(" and t.cnames  like ? ");
	     sql.append(" or t.ccode like ? ) t");
//	     sql.append(" where  ROWNUM <= 10");
		 sql.append(" order by ccode limit 10");
		
		dataSouceList = o2oSdDao.findObjectsList(sql.toString(),"%"+keywords+"%","%"+keywords+"%");
		

		return dataSouceList;
	}
	
	public List<EadbEabaCustomerNew> getCustomerDataSouce1(String keywords) {
		List<EadbEabaCustomerNew> dataSouceList = new ArrayList<>();
		StringBuffer sql = new StringBuffer("select * from (select t.cno as cno ,t.cname as cname,t.cnames as cnames,t.ccode as ccode from eaba_customer_new t where t.sts='PAS' and t.ctype='2'"); 
		//sql.append(" and cname  like ? ");
		if(StringUtil.isNotBlank(keywords)){
			sql.append(" and t.cnames  like ? ");
		     sql.append(" or t.ccode like ? ) t");
//		     sql.append(" where  ROWNUM <= 10");
		     sql.append(" order by ccode limit 10");
		     dataSouceList = o2oSdDao.findEntitys(sql.toString(),EadbEabaCustomerNew.class,"%"+keywords+"%","%"+keywords+"%");
		}else{
			 sql.append(" ) t");
			 sql.append(" order by ccode limit 10");
			 dataSouceList = o2oSdDao.findEntitys(sql.toString(),EadbEabaCustomerNew.class);
		}
		return dataSouceList;
	}
	
	
}
